<div class="row">
<div class="span12">      		
	   		
	<div class="widget ">
		<div class="widget-header">
			<i class="icon-plus"></i>
 			<h3>添加任务</h3>
		</div> <!-- /widget-header -->

		<div class="widget-content">
		
		<div class="alert alert-danger hide" role="alert"></div>

		<form id="add-task" action="{{urlfor "TaskController.Add"}}" method="post" class="form-horizontal">
			<fieldset>
				
				<div class="control-group">											
					<label class="control-label" for="task_name">任务名称</label>
					<div class="controls">
						<input type="text" name="task_name" class="span6" id="task_name">
					</div>				
				</div>
								
				<div class="control-group">											
					<label class="control-label" for="description">任务说明</label>
					<div class="controls">
						<textarea name="description" class="span6" id="description" rows="3"></textarea>
					</div> <!-- /controls -->				
				</div> <!-- /control-group -->
				
				<div class="control-group">											
					<label class="control-label" for="group_id">分组</label>
					<div class="controls">
						<select name="group_id" id="group_id">
							<option value="0">未分组</option>
							{{range $k, $v := .groups}}
							<option value="{{$v.Id}}">{{$v.GroupName}}</option>
							{{end}}
						</select>
					</div>				
				</div>
				
				<div class="control-group">											
					<label class="control-label">是否只允许一个实例</label>
					<div class="controls">
						<label class="radio inline">
							<input type="radio" value="0" name="concurrent" checked> 是
						</label>
						<label class="radio inline">
							<input type="radio" value="1" name="concurrent"> 否
						</label>
						<p class="help-block">设为“是”的话，如果该任务在上一个时间点还没执行完，则略过不执行</p>
					</div>	<!-- /controls -->			
				</div> <!-- /control-group -->
				
				<div class="control-group">											
					<label class="control-label" for="cron_spec">cron表达式</label>
					<div class="controls">
						<input type="text" name="cron_spec" class="span6" id="cron_spec" value="">
						<a href="{{urlfor "HelpController.Index"}}" target="_blank">参见使用帮助</a>
					</div> <!-- /controls -->				
				</div> <!-- /control-group -->
				
				
				<div class="control-group">											
					<label class="control-label" for="command">命令脚本</label>
					<div class="controls">
						<textarea name="command" class="span6" id="command" rows="6"></textarea>
					</div> <!-- /controls -->				
				</div> <!-- /control-group -->
				
				<div class="control-group">											
					<label class="control-label" for="timeout">超时设置</label>
					<div class="controls">
						<input type="text" name="timeout" class="span1" id="timeout" value="0"> 秒
						<span class="help-block">不设置的话，默认超时时间为1天</span>
					</div> <!-- /controls -->				
				</div> <!-- /control-group -->
				
				<div class="control-group">											
					<label class="control-label">邮件通知</label>
					<div class="controls">
						<label class="radio inline">
							<input type="radio" value="0" name="notify" checked> 不通知
						</label>
						<label class="radio inline">
							<input type="radio" value="1" name="notify"> 执行失败时通知
						</label>
						<label class="radio inline">
							<input type="radio" value="2" name="notify"> 执行结束时通知
						</label>
					</div>	<!-- /controls -->			
				</div> <!-- /control-group -->
				
				<div class="control-group notify_email hide">											
					<label class="control-label" for="notify_email">通知邮件抄送人</label>
					<div class="controls">
						<textarea name="notify_email" class="span6" id="notify_email" rows="6"></textarea>
						<p class="help-block">每行一个email地址，如果不需要抄送给其他人请留空</p>
					</div> <!-- /controls -->				
				</div> <!-- /control-group -->
		
				<br />
				
					
				<div class="form-actions">
					<button type="submit" class="btn btn-primary">保 存</button> 
					<a href="{{urlfor "TaskController.List"}}" class="btn">返 回</a>
				</div> <!-- /form-actions -->
			</fieldset>
		</form>

		</div>
	</div>
</div>
</div>

<script>
$(function () {
	$("form").submit(function () {
		$(".alert").hide();
		$("button[type='submit']").attr('disabled', true);
		$.post('{{urlfor "TaskController.Add"}}', $(this).serialize(), function (out) {
			if (out.status == 0) {
				window.location.href = '{{urlfor "TaskController.List"}}';
			} else {
				$(".alert").text(out.msg);
				$(".alert").show();
				$("button[type='submit']").attr('disabled', false);
			}
		}, "json");
		return false;
	});
	$("input[name='notify']").click(function () {
		if ($(this).val() > 0) {
			$('.notify_email').removeClass('hide');
		} else {
			$('.notify_email').addClass('hide');
		}
	});
});
</script>